import { organizationTree } from '@/api/brac/organization';
export function useOrganizationTree(options = {}) {
  const { initData = [], manual = false, onSuccess = () => {}, onError = console.error } = options;
  const state = reactive({
    data: initData,
    error: null
  });
  const run = async () => {
    try {
      const { data, code } = await organizationTree();
      if (code === 200) {
        onSuccess();
        state.data = data;
      }
    } catch (error) {
      onError();
      state.error = error;
    }
  };
  onMounted(() => {
    if (!manual) {
      run();
    }
  });
  return {
    ...toRefs(state),
    run
  };
}
